package com.stars.controller.system;

import com.stars.entity.dto.system.SysAreaDTO;
import com.stars.services.system.SysAreaConfigServices;
import com.stars.entity.system.SysAreaEntity;
import com.stars.services.system.SysAreaAccessServices;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.stars.common.annotation.Log;
import com.stars.common.base.BaseMsg;
import com.stars.common.ObjectCopyUtils;
import com.stars.common.base.BaseConstant;
import com.stars.common.base.ResultMsg;
import com.stars.controller.BaseController;
import com.stars.common.enums.OperationType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;

import com.stars.common.valid.AddView;
import com.stars.common.valid.UpdateView;
import com.github.pagehelper.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
/**
 * @Title: 全国行政区数据 mybatis dao
 * @author DJ
 * @date 2019-11-07
 * @version V1.0
 *
 */
@Slf4j
@RestController
@RequestMapping("/sysAreaCtl")
@Api(tags ="全国行政区数据")
public class SysAreaCtl extends BaseController{
   @Autowired
   private SysAreaAccessServices  sysAreaAccessServicesImpl;
   @Autowired
   private SysAreaConfigServices  sysAreaConfigServicesImpl;

   /**
   *  分页查询
   * @param pageNum 起始页
   * @param pageSize 大小
   * @return 分页数据
   * @throws Exception
   */
   @GetMapping("/pageList")
   @ApiOperation(value = "全国行政区数据"+BaseMsg.MODULAR_PAGE,notes ="全国行政区数据"+ BaseMsg.MODULAR_PAGE)
   @Log(detail = "全国行政区数据"+ BaseMsg.MODULAR_PAGE,operationType = OperationType.SELECT)
   public PageInfo<SysAreaDTO> pageSysAreaList(Integer pageNum, Integer pageSize, SysAreaDTO dto,HttpServletRequest request) throws Exception{
  
        return sysAreaAccessServicesImpl.pageList(pageNum,pageSize,dto);

   }

    /**
    * 保存
    * @param entityName
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/add")
    @ApiOperation(value = "全国行政区数据"+ BaseMsg.MODULAR_ADD,notes = "全国行政区数据"+BaseMsg.MODULAR_ADD)
    @Log(detail = "全国行政区数据"+BaseMsg.MODULAR_ADD,operationType = OperationType.INSERT)
    public ResultMsg addSysArea(@Validated({AddView.class}) SysAreaEntity entityName,HttpServletRequest request) throws Exception{
        return sysAreaConfigServicesImpl.insertSelective(entityName);
    }
    /**
    * 更新
    * @param updateEntityDto
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/update")
    @ApiOperation(value = "全国行政区数据"+ BaseMsg.MODULAR_UPDATE,notes = "全国行政区数据"+ BaseMsg.MODULAR_ADD)
    @Log(detail = "全国行政区数据"+ BaseMsg.MODULAR_UPDATE,operationType = OperationType.UPDATE)
    public ResultMsg updateSysArea(@Validated({UpdateView.class}) SysAreaEntity updateEntityDto,HttpServletRequest request) throws Exception{
        SysAreaEntity entity = sysAreaAccessServicesImpl.selectById(updateEntityDto.getId());
        ObjectCopyUtils.copyPropertiesIf(updateEntityDto,entity, BaseConstant.UPDATE);
        return sysAreaConfigServicesImpl.updateSelectiveById(entity);
    }

    /**
    * 根据id查询
    * @param id
    * @return 查询对象
    * @throws Exception
    */
    @GetMapping(value = "/findById")
    @ApiOperation(value = "全国行政区数据"+ BaseMsg.MODULAR_FIND_ID,notes = "全国行政区数据"+BaseMsg.MODULAR_FIND_ID)
    @Log(detail = "全国行政区数据"+ BaseMsg.MODULAR_FIND_ID,operationType = OperationType.SELECT)
    public ResultMsg findSysAreaById(String id) throws Exception{
        SysAreaEntity entityName = sysAreaAccessServicesImpl.selectById(id);
         return ResultMsg.success(entityName);
    }

     /**
     * 删除
     * @param ids
     * @return 成功失败
     * @throws Exception
     */
     @PostMapping(value = "/delById")
     @ApiOperation(value = "全国行政区数据"+BaseMsg.MODULAR_DEL,notes ="全国行政区数据"+BaseMsg.MODULAR_DEL)
     @Log(detail ="全国行政区数据"+BaseMsg.MODULAR_DEL,operationType = OperationType.DELETE)
     public ResultMsg delSysAreaById(String ids) throws Exception{
        return sysAreaConfigServicesImpl.deleteByIds(ids.split(BaseConstant.SPOT));

     }




}